
import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import Vuex from 'vuex'
import store from './store/index'

Vue.use(ElementUI);
Vue.use(VueRouter)
Vue.use(Vuex)

Vue.prototype.axios = axios;

Vue.config.productionTip = false

//路由跳转之前钩子函数 
router.beforeEach((to, from, next) => {
  let isLogin = sessionStorage.getItem('isLogin')
  console.log('isLogin' + isLogin);
  // 注销
  if (to.path == '/logout') {
    // 清空
    sessionStorage.clear();
    next({ path: '/login' })
  } else if (to.path == 'login') {
    if (isLogin != null) {
      next({ path: '/main' })
    }
  } else if (isLogin == null) {
    next({ path: '/login' })
  }
  next();
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
